<?php
error_reporting(1);


$movtypes	= array("mov","avi","mpg","mpeg","divx","ogm","mp4","mkv","m4v","mp4v");	// What are movie file extensions
$startdir	= getcwd();

$forcexml		= false;											// Force creation of XML files, even if already existing
$forcecover		= false;											// Force creation of cover files, even if already existing
$repaircover	= false;											// Repair cover symlinks (unlink + new symlink)
$getsubs		= false;											// Get subtitles for the movies

if(isset($argv[1])){ // Directory is given
	$subdirname = $argv[1];

	$imdbnr		= 0;

		$temp = explode("/",$subdirname);
		$movie = $temp[count($temp)-2];
		$movie   = preg_replace("/\s*?\(.*/","",$movie);		// Remove everything after first bracket (year, rip type, ...)
		if(file_exists($subdirname."/movietitle.txt")){	// Cached real title
			$temp	= file($subdirname."/movietitle.txt");
			$movie	= trim($temp[0]);
		}

		if(file_exists($subdirname."imdbnr.txt")){		// Cached IMDB nr
			$temp	= file($subdirname."imdbnr.txt");
			$imdbnr	= trim($temp[0]);
		}else{
			require ("imdbsearch.class.php");
			$search = new imdbsearch();
			$search->setsearchname ($movie);
			$results = $search->results();
			foreach ($results as $res) {
				if(strtolower($res->title()) == '"'.strtolower($movie).'"'){
					$imdbnr = $res->imdbid();
					break;
				}
			}

			if($imdbnr > 0){
				$temp	= fopen($subdirname."imdbnr.txt","w");
				fwrite($temp, $imdbnr);
			}
		}
		
	echo $imdbnr;
	exit;
}


exit;

?>